package com.atguigu.classroom.vod.controller;


import com.atguigu.classroom.model.vod.Course;
import com.atguigu.classroom.result.Result;
import com.atguigu.classroom.vo.vod.CourseFormVo;
import com.atguigu.classroom.vo.vod.CoursePublishVo;
import com.atguigu.classroom.vo.vod.CourseQueryVo;
import com.atguigu.classroom.vod.service.CourseService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-07-10
 */
@Api(tags = "课程接口")
@RestController
@RequestMapping("/admin/vod/course/")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @ApiOperation("点播视频列表")
    @GetMapping("{page}/{limit}")
    public Result courseList(@PathVariable int page,
                             @PathVariable int limit,
                             CourseQueryVo courseQueryVo){
        Page<Course> coursePage=courseService.getCoursePage(page,limit,courseQueryVo);
        return Result.ok(coursePage);
    }
    @ApiOperation("添加课程基本信息")
    @PostMapping("save")
    public Result save(@RequestBody CourseFormVo courseFormVo){
        Long courseId=courseService.saveCourseInfo(courseFormVo);
        return Result.ok(courseId);
    }
    @ApiOperation("根据id查询课程信息")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        CourseFormVo courseFormVo=courseService.getCourseInfoById(id);
        return Result.ok(courseFormVo);
    }
    @ApiOperation("修改课程信息")
    @PostMapping("update")
    public Result update(@RequestBody CourseFormVo courseFormVo){
        Long courseId=courseService.updateCourseFormVo(courseFormVo);
        return Result.ok(courseId);
    }
    @ApiOperation("id查询发布课程信息")
    @GetMapping("getCoursePublishVo/{id}")
    public Result getCoursePublishVo(@PathVariable Long id){
        CoursePublishVo coursePublishVo=courseService.getCoursePublishVo(id);
        return Result.ok(coursePublishVo);
    }
    @ApiOperation("课程最终发布")
    @PutMapping("publishCourseById/{id}")
    public Result publishCourse(@PathVariable long id){
        courseService.publishCourse(id);
        return Result.ok(null);
    }
    @ApiOperation("删除课程")
    @DeleteMapping("remove/{id}")
    public Result removeCourse(@PathVariable Long id){
        courseService.removeCourse(id);
        return Result.ok(null);
    }
    @GetMapping("findAll")
    public Result findAll() {
        List<Course> list = courseService.findlist();
        return Result.ok(list);
    }
}

